<template>
	<div id="tmpl">
		<div id="cate">
			<ul v-bind="{style:'width:'+ulWidth+'px'}">
				<li @click="getimgs(0)">全部</li>
				<li v-for="item in cates" @click="getimgs(item.id)" v-text="item.title"></li>
			</ul>
		</div>
		<div id="imglist">
			<ul>
			  <li v-for="item in list">
				<router-link v-bind="{to:'/photo/photoinfo1/'+item.id}">
			    <img v-lazy="item.img_url">
			    <div id="desc">
			    	<h5>{{item.title}}</h5>
			    	<p>{{item.zhaiyao}}</p>
			    </div>
			    </router-link>
			  </li>
			</ul>
		</div>
	</div>
</template>
<script>
import common from '../../kits/common.js';
import {Toast} from 'mint-ui';
	export default{
		data(){
			return{
				cates:[],
				list:[],
				ulWidth:320
			}
		},
		created(){
			this.getcates();
			var all=0;
			this.getimgs(all);
		},
		methods:{
			getcates(){
				var url=common.apidomain+'/api/getimgcategory';
				this.$http.get(url).then(function (response) {
					var data = response.body;
					if (data.status!=0) {
						Toast(data.message);
						return;
					}
					var w= 62;
					var count=data.message.length + 1;
					this.ulWidth=w*count;
					this.cates=data.message;
				})
			},
			getimgs(cateid){
				cateid=cateid||0;
				var url=common.apidomain+'/api/getimages/'+cateid;
				this.$http.get(url).then(function (response) {
					var data = response.body;
					if (data.status!=0) {
						Toast(data.message);
						return;
					}
					this.list=data.message;
				})
			}
		}

	}
</script>
<style scoped>
	#cate {
		width: 375px;
		max-width: 375px;
		overflow-x:auto;
	}
	#cate ul {
		/*width: 750px;*/
		margin: 0;
		padding-left: 5px;
	}
	#cate li {
		float: left;
		list-style: none;
		font-size: 14px;
		margin-left: 6px;
		color: #0049ff;
	}
	#imglist ul {
		padding-left: 0;
	}
	#imglist li {
		list-style: none;
		position: relative;
	}
	#imglist img{
		width: 100%;
		height: 300px;
	}
	#desc{
		width: 100%;
		background-color: rgba(0,0,0,.2);
		position: absolute;
		bottom: 2px;
		left: 0px;
	}
	#desc h5 {
		color: #fff;
		font-weight: 700;
	}
	#desc p {
		color: #fff;
	}
	image[lazy=loading] {
	  width: 40px;
	  height: 300px;
	  margin: auto;
	}
</style>